@extends('admin.layouts.header_other')
@section('title',"后台管理系统")
@section('content')
    <style>
        .serach_input{ width: 180px; margin-right: 5px;}
        .padding_top{ margin-top: 0px;}
    </style>
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script type="text/html" id="toolbarDemo">
        <div class="">
            <div class="layui-input-item">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm padding_top" lay-event="countyInAdd">添加</button>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm padding_top" lay-event="countyInAdd">刷新</button>
                </div>
                <div  class="layui-inline">
                    <input type="text" name="title" placeholder="请输入角色名称" autocomplete="on" class="layui-input serach_input layui-btn-sm ">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm padding_top" >搜索</button>
                </div>
            </div>

        </div>
    </script>
    <script type="text/html" id="switchTpl">
        <input type="checkbox" name="sex" value="" lay-skin="switch" lay-text="屏蔽|开启" lay-filter="">
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="{{asset('attach/js/layui.all.js')}}"></script>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#test'
                ,data:[
                    {
                        "id":1,
                        'title':"admin",
                        "publish":"超级管理员",
                        "publish_time":'最高权限',
                        "hits":'2019-10-12 12:13:14',
                        "dian":'2019-10-12 12:13:14',
                        "is_up":1,
                    },
                ]
                // ,url:'/test/table/demo1.json'
                ,toolbar: '#toolbarDemo'
                ,title: '后台用户管理'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                    ,{field:'title', title:'角色标识',width:150,sort:true}
                    ,{field:'publish', title:'角色名称', width:250}
                    ,{field:'publish_time', title:'角色描述', width:280, sort: true}
                    ,{field:'hits', title:'创建时间', width:200,sort:true}
                    ,{field:'dian', title:'修改时间',width:200,sort:true}
                    ,{field:'is_up', title:'是否开启', width:105, templet: '#switchTpl', unresize: true}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                ]]
                ,page: true
                ,count:20
                ,limit:12
                ,loading:true
                ,size:'lg'
            });
            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'countyInAdd':
                        var openwin=layer.open({
                            type:2,
                            title:"添加角色",
                            content:"{{route('admin.role.add')}}",
                            area:['100%','100%'],
                            maxmin:true,
                        });
                        layer.full(openwin);
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layer.prompt({
                        formType: 2
                        ,value: data.email
                    }, function(value, index){
                        obj.update({
                            email: value
                        });
                        layer.close(index);
                    });
                }
            });
        });
    </script>
@endsection
